<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload = function (){
  var aBtn = document.getElementsByTagName('input');
  var aP = document.getElementsByTagName('p');
  var arr = ['张三','李四','王五'];
  
  for (var i=0;i<aBtn.length;i++){
	aBtn[i].index = i;	//不能把索引值放下面
	aBtn[i].onOff = true;
	aBtn[i].onclick = function (){
    //this.index = i;  不能这么写
	//aler(this.index);这样写的话始终出来的都是3
	if (this.onOff){
	  aP[this.index].innerHTML += arr[this.index];   //不能写aP[i]，因为p标签的个数并没有找出来，而且i已经赋值出去了，因此匹配的话还是要用索引值
	  this.onOff = false;
	}
	}
  }
}
</script>
</head>
<body>
<input type="button" value="btn1">
<input type="button" value="btn2">
<input type="button" value="btn3">
<p>1:</p>
<p>2:</p>
<p>3:</p>
<p>4：</p>
</body>
</html>
